<!-- HTML header for doxygen 1.8.5-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.6"/>
<title>MyoKit 0.4.0: Getting Started</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
  $(window).load(resizeHeight);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>
<link href="customdoxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<div id="projectnumber">MyoKit &ndash; 0.4.0</div>
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img src="logo-black.png"/></td>
   <td>        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
</td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.6 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('_getting__started.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Properties</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Groups</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Pages</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">Getting Started </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><h2>Supported Devices </h2>
<p>In order to use MyoKit, you need a device that is running iOS 7 or later and supports BLE. They are as follows:</p>
<ul>
<li>iPhone 4S or later</li>
<li>iPad 3rd gen or later</li>
<li>iPod Touch 5th gen or later</li>
<li>iPad mini</li>
</ul>
<h2>Adding MyoKit to a Project </h2>
<ul>
<li>Drag <b>MyoKit.framework</b> into your Xcode project.</li>
<li>Under <code>Project File &gt; Build Phases &gt; Link Binaries With Libraries</code>, add <b>MyoKit.framework</b>, <b>CoreBluetooth.framework</b>, and <b>SystemConfiguration.framework</b>.</li>
</ul>
<h2>Instantiating the Hub </h2>
<p>In your <b>AppDelegate.m</b>, add <code>#import &lt;<a class="el" href="_myo_kit_8h_source.html">MyoKit/MyoKit.h</a>&gt;</code>.</p>
<p>In your AppDelegate's <code>application:didFinishLaunchingWithOptions:</code> method, add the following line: </p>
<pre class="fragment">- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    /**
    Default code.


    [TLMHub sharedHub];
    return YES;
}
</pre><h2>Managing Myos </h2>
<p>The Myo iOS SDK comes with a built in view controller for connecting to a particular Myo called the <a class="el" href="interface_t_l_m_settings_view_controller.html">TLMSettingsViewController</a>. There are several ways to create the view controller, but when it's being presented to the user, it must be in a UINavigationController. Here's several ways to show users the Myo settings VC: </p>
<pre class="fragment">// Pushing it on an existing navigation controller
- (void)pushMyoSettings {
    TLMSettingsViewController *settings = [[TLMSettingsViewController alloc] init];

    [self.navigationController pushViewController:settings animated:YES];
}

// Presenting modally
- (void)modalPresentMyoSettings {
    UINavigationController *settings = [TLMSettingsViewController settingsInNavigationController];

    [self presentViewController:settings animated:YES completion:nil];
}

// Presenting in a Popover (iPad only)
- (void)popoverPresentMyoSettings {
    // Make sure to hold a strong reference to your popover so it doesn't get dealloc'ed when it's presented.
    self.popover = [TLMSettingsViewController settingsInPopoverController];

    [self.popover presentPopoverFromBarButtonItem:settingsButton 
                         permittedArrowDirections:UIPopoverArrowDirectionAny 
                                         animated:YES];
}
</pre><p>Alternatively, you can attach to a Myo programatically using <code>- (void)attachToAdjacent</code> or <code>- (void)attachByIdentifier:(NSUUID *)identifier</code>. </p>
<pre class="fragment">// Connecting to a Myo with attachToAdjacent
- (void)attachToAdjacentMyo {
    [[TLMHub sharedHub] attachToAdjacent];
}

// Connecting to a Myo by its identifier
// The identifier for a Myo can be retrieved from the TLMMyo's identifier property
- (void)attachToMyoByIdentifier:(NSUUID *)identifier {
    [[TLMHub sharedHub] attachByIdentifier:identifier];
}
</pre><h2>Locking and Unlocking Myo </h2>
<p>Normally, Myo is locked until the user performs the unlock pose. Once the unlock pose is performed, your application will begin receiving pose events until Myo locks itself after a short period of time. There are two policies your application can choose from when it comes to locking.</p>
<h3>Locking Policies</h3>
<ul>
<li><code>TLMLockingPolicyStandard</code> Using this policy means Myo will be locked until the user performs the unlock pose. This is the default policy.</li>
<li><code>TLMLockingPolicyNone</code> Using this policy means you will always receive pose events, regardless of Myo's unlock state.</li>
</ul>
<p>You can set the locking policy for your app like so: </p>
<pre class="fragment">[[TLMHub sharedHub] setLockingPolicy:TLMLockingPolicyNone];
</pre><h3>Unlocking a Myo</h3>
<p>If your application would like to have more control over locking, you can use the appropriate methods on <code><a class="el" href="interface_t_l_m_myo.html">TLMMyo</a></code>.</p>
<p>In order to extend the unlock timer, simply unlock Myo like so: </p>
<pre class="fragment">- (void)extendUnlockForMyo:(TLMMyo *)myo {
    [myo unlockWithType:TLMUnlockTypeTimed];
}
</pre><p>If your application wants Myo to stay unlocked until explicitly locked, you can use <code>TLMUnlockTypeHold</code> like so: </p>
<pre class="fragment">- (void)holdUnlockForMyo:(TLMMyo *)myo {
    [myo unlockWithType:TLMUnlockTypeHold];
}

- (void)endHoldUnlockForMyo:(TLMMyo *)myo immediately:(BOOL)immediately {
    if (immediately) {
        [myo lock];
    } else {
        [myo unlockWithType:TLMUnlockTypeTimed];
    }
}
</pre><p><b>Note:</b> In order to lock the Myo once again, your application would need to either do a timed unlock, or lock immediately.</p>
<h2>Receiving Pose and Orientation Events </h2>
<p>Now that the SDK is integrated to your project and the device is trained, it's time to start receiving data. New data notifications are received through the <b>NSNotificationCenter</b> built into iOS.</p>
<p>Poses can be received as outlined below: </p>
<pre class="fragment">- (void)viewDidLoad {
    [super viewDidLoad];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(didReceivePoseChange:)
                                                 name:TLMMyoDidReceivePoseChangedNotification
                                               object:nil];
}

- (void)didReceivePoseChange:(NSNotification*)notification {
    TLMPose *pose = notification.userInfo[kTLMKeyPose];

    //TODO: do something with the pose object.
}
</pre><p>A stream of orientation data can be received as outlined below: </p>
<pre class="fragment">- (void)viewDidLoad {
    [super viewDidLoad];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(didReceiveOrientationEvent:)
                                                 name:TLMMyoDidReceiveOrientationEventNotification
                                               object:nil];
}

- (void)didReceiveOrientationEvent:(NSNotification*)notification {
    TLMOrientationEvent *orientation = notification.userInfo[kTLMKeyOrientationEvent];

    //TODO: do something with the orientation object.
}
</pre><h2>Enabling Events in the Background </h2>
<p>In order to receive Myo events while your app is in the background, you must first follow these steps:</p>
<ol type="1">
<li>Set Project File &gt; Capabilities &gt; Background Modes to "On".</li>
<li>Check "Uses Bluetooth LE accessories".</li>
<li>On the <a class="el" href="interface_t_l_m_hub.html">TLMHub</a>, set the shouldNotifyInBackground property to "YES".</li>
</ol>
<p>For example: </p>
<pre class="fragment">[[TLMHub sharedHub] setShouldNotifyInBackground:YES];
</pre><h2>Usage Data </h2>
<p>The Myo iOS SDK sends some usage data to Thalmic Labs. To opt out of the data being sent, set the <code>shouldSendUsageData</code> property to <code>NO</code>: </p>
<pre class="fragment">[[TLMHub sharedHub] setShouldSendUsageData:NO];
</pre><p>It is your responsibility to expose a way for users to set this, if desired. </p>
</div></div><!-- contents -->
</div><!-- doc-content -->
<!-- HTML footer for doxygen 1.8.5-->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Copyright &copy; 2013 Thalmic Labs Inc. Confidential and not for redistribution. See LICENSE.txt.</li>
  </ul>
</div>
</body>
</html>
